package com.lyl.serviceucenter.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lyl.commonutils.R;
import com.lyl.serviceucenter.entity.Member;
import com.lyl.serviceucenter.service.MemberService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.Banner;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/serviceucenter/member")
public class MemberController {


    @Autowired
    MemberService memberService;

    @PostMapping("/updateStatusById/{id}/{memberStatus}")
    public R updateStatusById(@PathVariable("id") Long id,@PathVariable("memberStatus") Boolean memberStatus) {
        if( memberService.updateStatusById(id,memberStatus)) {
            return R.ok().message("操作成功");
        }
        return R.error().message("操作失败");
    }

    @ApiOperation(value = "获取所有客户信息")
    @PostMapping("{page}/{limit}")
    public R index(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Long page,

            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Long limit,
            @RequestBody(required = false) Member member) {

        Page<Member> pageParam = new Page<>(page, limit);


        memberService.pageQuery(pageParam, member);
        List<Member> records = pageParam.getRecords();

        long total = pageParam.getTotal();

        return  R.ok().data("total", total).data("rows", records);




    }

    @GetMapping("/getCountByDay/{date}")
    public R getCountByDay(@PathVariable("date") String date){
        Long count= memberService.getMemberCountByDay(date);
        return R.ok().data("count",count);
    }

}
